﻿using DotNetty.Framework;
using DotNetty.Framework.BaseModel;
using System.IO;
using System.Threading.Tasks;

namespace iTool.Connector.HttpWorkers
{
    public class DownloadFileWorker : IHttpWorker
    {

        public int SecondOfTimeOut { get; set; } = 10;

        public async Task DoWorking<THttpContext>(THttpContext context) where THttpContext : AbstractHttpContext, new()
        {
            // 模拟并发读取
            Parallel.For(0, 20, e =>
            {
                FileStream fs = new FileStream("./face.png", FileMode.Open, FileAccess.Read);
                context.ResponseBody = fs;
            });


            await Task.CompletedTask;
        }

        public bool IsUseWorking<THttpContext>(THttpContext context) where THttpContext : AbstractHttpContext, new()
        {
            return context.Path.ToLower() == "/downloadfile";
        }

    }
}
